package com.test.mytest.thread;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.locks.Lock;

public class LockTestThread extends Thread {
	Lock lock;
	String name;
	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm:SSS");
	public LockTestThread(Lock lock,String name) {
		this.lock=lock;
		this.name=name;
	}
	@Override
	public void run() {
		System.out.println(name);
		try {
//			if (!tryLock) {
//				lock.unlock();
//			}
			lock.lock();
			boolean tryLock = lock.tryLock();
			System.out.println(tryLock+"========="+sdf.format(new Date())+"===线程===="+name+"===="+getName());
			wait();
		} catch (InterruptedException e) {
			System.out.println(e);
//			lock.unlock();
		}
	}
	
	public void unLock(){
		lock.unlock();
	}
}
